<template>
  <div class="search-history">
    <van-cell title="历史记录">
      <template slot="default">
        <div v-if="isDeleteShow">
          <!-- <span @click="searchHistories=[]">全部删除</span>  -->
          <span @click="$emit('update:searchHistories',[])">全部删除</span>
          <span @click="isDeleteShow=false">完成</span>
        </div>
        <van-icon  v-else name="delete-o" @click="isDeleteShow=true"/>
      </template>
    </van-cell>

    <van-cell :title="item" v-for="(item,i) in searchHistories" :key="i" @click="clickHistory(item,i)">
      <template slot="default">
        <van-icon name="close" v-show="isDeleteShow"  />
      </template>
    </van-cell>
  </div>
</template>

<script>
export default {
  name: 'searchHistory',
  props: {
    searchHistories: {
      type: Array,
      required: true,
    },
  },
  data() {
    return {
      isDeleteShow:false
    }
  },
  methods: {
    clickHistory(item,i){
      if(this.isDeleteShow){
        // 删除历史记录
         this.searchHistories.splice(i,1)
      }else{
        // 展示历史搜索结果
        this.$emit("search",item)
      }
     
    }
  },
  created() {},
}
</script>

<style lang="" scoped>
</style>